<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>会员荣誉身份列表</title>
    <link rel="stylesheet" href="https://www.layuicdn.com/layui-v2.5.6/css/layui.css" media="all">
    <style>
        .productFxList-container {
            padding: 20px;
        }

        td[data-field="imgUrl"] div,
        td[data-field="negativeImgUrl"] div {
            height: 120px;
        }

        .lay-form {
            padding: 20px;
        }

        .productFxList-container {
            background-color: #fff;
        }

        .bar {
            display: flex;
            justify-content: flex-start;
            align-items: flex-end;
        }

        .searchInput {
            display: flex;
            align-items: flex-end;
        }

        .searchInput input {
            width: 200px;
        }

        .searchInput .layui-form-label {
            padding: 9px 0;
        }

        .bar .layui-form-label {
            padding: 0;
            padding-bottom: 4px;
            text-align: left;
        }

        .bar .layui-inline {
            margin-right: 20px;
        }

        .layui-table img {
            max-width: 200px;
            object-fit: contain;
        }

        .layui-table-cell {
            height: auto;
        }

        .fxProduct-container {
            padding: 20px;
        }

        .fxProduct-container {
            background-color: #fff;
        }
        .fxProduct-container form {
            width: 800px;
            margin: 0 auto;
            padding: 30px;
            border: 1px solid #eee;
        } 

        #inputContainer {
            margin-bottom: 20px;
            /* border: 1px solid #eee;   */
            padding: 0 40px
        }
 
        .layui-form-label {
            width: 140px;
        }
        .layui-input-block {
            margin-left: 170px;
        }
        #inputContainer .layui-input-block  {
            margin: 0;
            padding: 10px;
            width: 19%;
        }
        #inputContainer li {
            display: flex;
            width: 100%;
            border-bottom: 1px solid #eee;
            align-items: center;
        }
        #inputContainer .layui-textarea {
            height: 38px !important;
        }
        #inputContainer .layui-input,  #inputContainer .layui-textarea {
            min-height: auto;
            border-radius: 5px;
            text-align: center;
        }
        .item .layui-form-label{
            text-align: center;
            border-bottom: 1px solid #eee;
            width: 122px;
        }
    </style>
</head>

<body>
    <div class="productFxList-container">
        <table lay-filter="productFxListTable" class="layui-hide" id="productFxListTable"></table>
    </div>

</body>

<!-- 添加 -->
<script type="text/html" id="toolbarDemo">
    <div class="bar">
        <div class="layui-btn-container" style="margin-bottom:-5px;">
            <button class="layui-btn layui-btn-normal layui-btn-sm" lay-event="add">添加</button>
        </div>
    </div>
</script>

<!-- 操作 -->
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
</script>

<script src="https://cdn.bootcdn.net/ajax/libs/layui/2.5.7/layui.all.min.js"></script>
<script src="../utils.js"></script>
<script src="../addProduct/layedit.js"></script>
<script>
    layui.use(['table', 'upload', 'form', 'jquery', "laydate"], function () {
        var table = layui.table,
            upload = layui.upload,
            form = layui.form,
            laydate = layui.laydate,
            $ = layui.jquery,
            layedit = layui.layedit;
            var editContext = "";

            table.render({
            elem: '#productFxListTable'
            , toolbar: "#toolbarDemo"
            , url: window.baseUrl + '/user/getVipConfigList'
            , method: 'get'
            , headers: {
                Authorization: localStorage.token
            }
            , response: {
                statusCode: 200 //规定成功的状态码，默认：0
            }
            , cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
            , parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": 200,
                    "count": res.total, //解析数据长度
                    "data": res.data //解析数据列表
                };
            }
            , request: {
                pageName: 'start' //页码的参数名称，默认：page
                , limitName: 'length' //每页数据量的参数名，默认：limit
            }
            , cols: [[
                { type: 'checkbox' }
                , { field: 'id', title: 'ID', width: 60, sort: true }
                , { field: 'vipName', title: '会员荣誉身份名称'}
                , { field: 'level', title: '会员荣誉身份级别'}
                , { field: 'distributionUserLevel', title: '分销商会员级别', width: 140  }
                , { field: 'distributionUserNum', title: '分销商数量', width: 140  }
                , { field: 'generations',  title: "业绩累积代数"}
                , { field: 'achievement',  title: "业绩金额"}
                , { field: 'des', title: '会员荣誉身份描述', templet: function (res) {
                        return res.des || '-'
                    } }
                , {
                    title: '状态', width: 70, templet: function (res) {
                        return res.status == 1 ? '<span class="layui-badge layui-bg-orange">停用</span>': '<span class="layui-badge layui-bg-green">正常</span>'
                    }
                }
                , { field: "createTime", title: '添加时间', width: 180 }
                , { title: '操作',  width: 70, toolbar: '#barDemo' }
            ]],
            page: false
        });

        laydate.render({
            elem: '#test1'
        });

        function showLayer(data) {
            layer.open({
                type: 1,
                title: "添加/编辑奖励配置",
                area: ['940px', '700px'], //宽高
                content: `
                    <div class="fxProduct-container">
                        <form class="layui-form" lay-filter="fxProduct">

                            <div class="layui-form-item">
                                <label class="layui-form-label"><span style="color:red; font-size:16px;">* </span>会员荣誉身份名称</label>
                                <div class="layui-input-block">
                                    <input type="text" name="vipName" lay-verify="required" lay-reqtext="会员荣誉身份名称是必填项，岂能为空？" placeholder="请输入会员荣誉身份名称"
                                        autocomplete="off" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label"><span style="color:red; font-size:16px;">* </span>会员荣誉身份级别</label>
                                <div class="layui-input-block">
                                    <input type="text" name="level" lay-verify="required|number" lay-reqtext="会员荣誉身份级别是必填项，岂能为空？" placeholder="请输入会员荣誉身份级别"
                                        autocomplete="off" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label"><span style="color:red; font-size:16px;">* </span>分销商会员级别</label>
                                <div class="layui-input-block">
                                    <input type="text" name="distributionUserLevel" lay-verify="required|number" lay-reqtext="分销商会员级别是必填项，岂能为空？" placeholder="请输入分销商会员级别"
                                        autocomplete="off" class="layui-input">
                                </div>
                            </div>
                             <div class="layui-form-item">
                                <label class="layui-form-label"><span style="color:red; font-size:16px;">* </span>分销商数量</label>
                                <div class="layui-input-block">
                                    <input type="text" name="distributionUserNum" lay-verify="required|number" lay-reqtext="分销商数量是必填项，岂能为空？" placeholder="请输入分销商数量"
                                        autocomplete="off" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label"><span style="color:red; font-size:16px;">* </span>业绩金额</label>
                                <div class="layui-input-block">
                                    <input type="text" name="achievement" lay-verify="required|number" lay-reqtext="业绩金额是必填项，岂能为空？" placeholder="请输入业绩金额"
                                        autocomplete="off" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label"><span style="color:red; font-size:16px;">* </span>业绩累积代数</label>
                                <div class="layui-input-block">
                                    <input type="text" name="generations" lay-verify="required|number" lay-reqtext="业绩累积代数是必填项，岂能为空？" placeholder="请输入业绩累积代数"
                                        autocomplete="off" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label"><span style="color:red; font-size:16px;">* </span>会员荣誉身份描述</label>
                                <div class="layui-input-block">
                                    <textarea placeholder="请输入会员荣誉身份描述" name="des" class="layui-textarea"></textarea>
                                </div>
                            </div>

                            


                            <input type="hidden" name="id" id="fxId" />

                            <div class="layui-form-item">
                                <label class="layui-form-label">状态</label>
                                <div class="layui-input-block" id="LAY-switch-check">
                                    <input type="checkbox" checked name="status" lay-skin="switch" lay-filter="switchTest" lay-text="启用|停用">
                                </div>
                            </div>
                    
                            
                            <div class="layui-form-item" style="text-align:center">
                                <div class="layui-input-block" style="margin-left: 0;">
                                    <button type="submit" class="layui-btn" lay-submit="" lay-filter="addfxProduct">立即提交</button>
                                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                </div>
                            </div>
                        </form>
                    </div>`,
                    success (layero, index){
                        form.render();
                        console.log(data);
                    }
            });
        }

        table.on('toolbar(productFxListTable)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case "add":
                    showLayer();
                    $('#fxId').val("");
                    // window.location.href = "../addProduct/addFxProduct.html";
                    break;
            };
        });
        

        // 编辑和删除
        table.on("tool(productFxListTable)", function (data) {
            switch (data.event) {
                case "edit":

                    showLayer(data.data);
                    data.data.status = data.data.status == 0 ?  true : false
                    form.val('fxProduct', data.data);
                    break;
            }
        })

        // 提交
        form.on("submit(addfxProduct)", function(obj) {
            obj.field.status = obj.field.status ? 0 : 1;

            // 编辑
            if (obj.field.id) {
                ajax({
                    path: "/user/updateVipConfig",
                    data: obj.field,
                    success: function (res) {
                        layer.closeAll();
                        layer.msg("编辑成功!")
                        table.reload("productFxListTable");
                    }
                }, $)
            } else {
                delete obj.field.id;

                ajax({
                    path: "/user/addVipConfig",
                    data: obj.field,
                    success: function (res) {
                        layer.closeAll();
                        layer.msg("添加成功!")
                        table.reload("productFxListTable");
                    }
                }, $)
            }

            return false;
        })
    });
</script>

</html>